package org.example.controller;

import org.example.entity.RechargePackages;
import org.example.service.RechargePackagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import org.example.common.ResponseEntity;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@CrossOrigin(origins = "*")
public class RechargePackagesController {
    @Autowired
    private RechargePackagesService rechargePackagesService;
    //查询全部套餐
    @GetMapping("/packages")
    public ResponseEntity<List<RechargePackages>> getAllRechargePackages() {
        List<RechargePackages> packages = rechargePackagesService.getAllRechargePackages();
        return ResponseEntity.success(packages);
    }
    @PostMapping("/updatepackage")
    public ResponseEntity<String> updateRechargePackage(@RequestBody RechargePackages rechargePackage) {
        try {
            String result = rechargePackagesService.updateRechargePackage(rechargePackage);
            return org.example.common.ResponseEntity.success(result);
        } catch (Exception e) {
            return org.example.common.ResponseEntity.fail("修改失败: " + e.getMessage());
        }
    }
}
